﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.ComponentModel;
using System.Collections.ObjectModel;
using HA.ModFlow.Domain.DomainLayer;

namespace HA.ModFlow.Controls
{
    public class GridConfiningBed : INotifyPropertyChanged
    {
        public GridConfiningBed(int index, bool isHave, bool isBottomLayer)
        {
            this._layIndex = index;
            this._isConfiningBedBelow = isHave;
            this._isNotBottomLayer = !isBottomLayer;
            
        }

        bool _isConfiningBedBelow;

        public bool IsConfiningBedBelow
        {
            get { return _isConfiningBedBelow; }
            set
            {
                _isConfiningBedBelow = value;
                OnPropertyChanged("IsConfiningBedBelow");
            }

        }

        int _layIndex;

        public int LayIndex
        {
            get { return _layIndex; }
        }

        bool _isNotBottomLayer;

        public bool IsNotBottomLayer
        {
            get { return _isNotBottomLayer; }
        }


        #region INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
                
            }
        }
        #endregion
    }


    public class GridConfiningBedCollection: ObservableCollection<GridConfiningBed>
    {
        public GridConfiningBedCollection(GridData gridData)
        {
            this._gridData = gridData;

            List<int> layerIndexs = new List<int>();
            layerIndexs = this._gridData.WaterGrid.GetLayerIndexList();

            List<bool> isConfiningBedBelow = new List<bool>();
            isConfiningBedBelow = this._gridData.WaterGrid.GetIsHaveConfiningBed();

            List<bool> isBottonLayer = new List<bool>();
            isBottonLayer = this._gridData.WaterGrid.GetIsBottomLayer();
            

            for (int i = 0; i < layerIndexs.Count; i++)
            {
                this._layers.Add(new GridConfiningBed(layerIndexs[i],isConfiningBedBelow[i],isBottonLayer[i]));
            }
        }

        List<GridConfiningBed> _layers = new List<GridConfiningBed>();

        public List<GridConfiningBed> Layers
        {
            get { return _layers; }
            set { _layers = value; }
        }

        GridData _gridData;

        public void SetConfiningBed(List<GridConfiningBed> layers)
        {
            List<bool> isHave=new List<bool>();
            foreach (GridConfiningBed layer in layers)
            {
                isHave.Add(layer.IsConfiningBedBelow);
            }

            this._gridData.WaterGrid.SetIsHaveConfiningBeds(isHave);
        }
    }
}
